//app.js
const ald = require('./utils/ald-stat.js')
import {
  obtain_openid,
  merchantProfile
} from '/api.js'
var app = getApp(); //获取App内部的信息
App({
  onLaunch: function () {
    this.getSystemInfo()
    this.updataApp()// 版本更新
    // 展示本地存储能力                                                                                                                
    var that = this;
    that.globalData.phone = wx.getStorageSync("phone")
    that.globalData.password = wx.getStorageSync("password")
    // 登录
    wx.login({
      success: res => {
        obtain_openid({
          code:res.code
        }).then(res =>{
          that.globalData.appid = res.data.data.openid    
          if (wx.getStorageSync("token")) {
            that.globalData.token = wx.getStorageSync("token")         
          }  
        })
      }
    })    
  },
  
  globalData: {
    userInfo: null,
    code: null,
    token: "",
    appid:'',
    hide_num:0,
    phone:'',
    password:'',
    guojia:'',
    name:"",
    isshow:false,
    is_name_updated:0,
    is_auth:"",
    is_bank_auth:"",
    is_identify:"",
    is_name_updated:"",
    is_iPhoneX:false,                imgurl:"https://v2.tool.growthupup.com/api/public/index/upload/uploadMerchant",
    product_id:"",
    activitylist:[]
  },
  getusername(){
    merchantProfile({
      token:app.globalData.token
    }).then(res=>{
      console.log(res)
    })
  },
  getSystemInfo(){
    var that=this
    wx.getSystemInfo({
      success(res) {
        if (res.model.indexOf("iPhone X") > -1){
          that.globalData.is_iPhoneX=true
        }
        console.log(res.model)
        console.log(that.globalData.is_iPhoneX)
      }
    })
  },
  updataApp: function () {//版本更新
    if (wx.canIUse('getUpdateManager')) {
      // console.log(wx.canIUse('getUpdateManager'))
      const updateManager = wx.getUpdateManager()
      updateManager.onCheckForUpdate(function (res) {
        if (res.hasUpdate) { // 请求完新版本信息的回调
          updateManager.onUpdateReady(function () {            
            wx.showModal({
              title: '更新提示',
              content: '新版本已经准备好，是否重启应用？',
              success: function (res) {
                console.log(res)
                if (res.confirm) {
                  updateManager.applyUpdate()
                }
              }
            })
          })
          updateManager.onUpdateFailed(function () {
            wx.showModal({// 新的版本下载失败
              title: '已经有新版本了哟~',
              content: '新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~',
            })
          })
        }
      })
    } else {
      wx.showModal({// 如果希望用户在最新版本的客户端上体验您的小程序，可以这样子提示
        title: '提示',
        content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
      })
    }
  },
  
})

// 倒计时
